package com.hontech.pastacooking.task.conn

import com.hontech.pastacooking.app.log
import com.hontech.pastacooking.app.runAppScope
import com.hontech.pastacooking.conn.Device
import com.hontech.pastacooking.conn.keepAlive
import kotlinx.coroutines.delay


private suspend fun safeKeep() {

    try {
        keepAlive()
        log("keep alive")
    } catch (e: Exception) {
        e.printStackTrace()
    }
}

fun runKeepTask() {
    runAppScope {
        while (true) {
            if (Device.isOpen()) {
                safeKeep()
            }
            delay(10 * 1000)
        }
    }
}

